<%-- 
    Document   : XemVanBanSoanThao
    Created on : Jun 10, 2011, 10:40:10 PM
    Author     : pdaitoan
--%>

<%@page import="com.google.appengine.api.blobstore.BlobstoreServiceFactory"%>
<%@page import="com.google.appengine.api.blobstore.BlobstoreService"%>
<%@page import="javax.jdo.Query"%>
<%@page import="java.util.List"%>
<%@page import="Servlet.PMF"%>
<%@page import="javax.jdo.PersistenceManager"%>
<%@page import="Entity.Document"%>
<%@page import="java.text.SimpleDateFormat"%>
<%@page import="Entity.ODoc"%>
<%@page import="DataAccess.ODocAccess"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <style type="text/css">
            @import "../css/main.css";
            @import "../css/menu.css";
            @import "../menu/menu_style.css";
            @import "../css/VanBanDi.css";
            .ui-widget{font-size:0.7em;}
            .ui-helper-hidden-accessible{clip:auto;}
        </style>
<%
    BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
%>

        <title>Xem VB đi</title>
    </head>
    <body>
        <%@include file="../header.jsp" %>
        <%
            Long ID = Long.parseLong(request.getParameter("OID"));
            ODocAccess odoc = new ODocAccess();
            ODoc entity = new ODoc();
            entity = odoc.getODocByID(ID);
            SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy");
        %>
        <div id="vbd">
        	Thông tin văn bản đi
        </div>
        <div id="vanbandi">
        	<form name="form1" action="/odoc" method="post" id="form1">
            <input type="hidden" name="action" value="publish"/>
            <input type="hidden" name="txtODocID" value="<% out.print(entity.getODocID()); %>"/>
                <table width="966" height="630" border="0" align="center" id="table">
                <tbody>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td id="td7">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td id="td7">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td id="td7">&nbsp;</td>
                </tr>
                <tr>
                  <td width="114" height="32">Số văn bản đi</td>
                  <td width="174" id="td"><% out.print(entity.getPubNum()); %></td>
                  <td width="5">&nbsp;</td>
                  <td width="100">Trả lời VB số</td>
                  <td width="164" id="td"><% out.print(entity.getIDocID()); %></td>
                  <td width="14">&nbsp;</td>
                  <td width="159">Ngày soạn thảo</td>
                  <td width="200" id="td"><% out.print(df.format(entity.getDraftDate())); %></td>
                </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="3" id="td2">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td colspan="3" id="td2">&nbsp;</td>
                </tr>
                <tr>
                  <td height="29">Tên nơi nhận</td>
                  <td colspan="3" id="td"><% out.print(entity.getReceivePlaceName()); %></td>
                  <td> &nbsp;&nbsp;&nbsp;&nbsp;Tên người nhận</td>
                  <td colspan="3" id="td"><% out.print(entity.getReceiveByName()); %></td>
                  </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="7" id="td3">&nbsp;</td>
                </tr>
                <tr>
                  <td height="63">Tựa đề</td>
                  <td colspan="7" id="td"><% out.print(entity.getSubject()); %></td>
                </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="7" id="td4">&nbsp;</td>
                </tr>
                <tr>
                  <td height="131">Nội dung tóm tắt</td>
                  <td colspan="7" id="td"><% out.print(entity.getBriefContent()); %></td>
                </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td colspan="7" id="td5">&nbsp;</td>
                </tr>
                <tr>
                  <td height="93">Ghi chú</td>
                  <td colspan="7" id="td"><% out.print(entity.getNotes()); %></td>
                </tr>
                <tr>
                  <td height="22">Toàn văn</td>
                  <td colspan="4">
                      <%
                        if (entity.getDocumentName() != null)
                        {
                            PersistenceManager pmf = PMF.get().getPersistenceManager();
                            //String query = "select from " + Document.class.getName();
                            Query q = pmf.newQuery(Document.class,"name == fname");
                            q.declareParameters("String fname");

                            List<Document> list = (List<Document>)q.execute(entity.getDocumentName().trim());
                            Document doc = new Document();
                            if (list.size() > 0)
                            {
                                doc = list.get(0);
                                out.println("<a href=\"/serve?blob-key=" + doc.getKey() + "\" target=\"_blank\">"+ doc.getName() +"</a>");
                            }
                            pmf.close();
                        }
                      %>
                  </td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td height="32">Người ký</td>
                  <td colspan="3" id="td">
                      <%
                        // Get FullNameByID
                        user = new UserAccess();
                        Long SignedID = Long.parseLong(entity.getSignByName().trim());
                        Account acc = new Account();
                        acc = user.getUserByID(SignedID);
                        if (acc != null)
                            out.print(acc.getFullname());
                      %>
                  </td>
                  <td>&nbsp;&nbsp;&nbsp;&nbsp;Tên người soạn thảo</td>
                  <td colspan="3" id="td"><% out.print(entity.getDraftUsername()); %></td>
                </tr>
                <tr>
                  <td height="16">&nbsp;</td>
                  <td id="td6">&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td colspan="2" id="td6">&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td height="32">Ngày ký</td>
                  <td id="td"><% out.print(df.format(entity.getSignDate())); %></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;&nbsp;&nbsp;&nbsp;Ngày phát hành</td>
                  <td colspan="2" id="td"><% out.print(df.format(entity.getPubDate())); %></td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td>&nbsp;</td>
                  <td colspan="2">
                  <%
                     String role = account.getRole();
                     if (role.trim().equals("director"))
                     {
                  %>
                        <input type="submit" name="btnPublish" id="button" value="Phát hành">
                  <%
                     }
                  %>
                      &nbsp;&nbsp;&nbsp;&nbsp;
                      <input type="button" id="button" value="Trở về" ONCLICK="history.go(-1)"></td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
  
                </tr>
                </tbody>
              </table>
   		  </form>
        </div>
    </body>
</html>
